<?php
/**
 * oscshop2 B2C电子商务系统
 *
 * ==========================================================================
 * @link      http://www.oscshop.cn/
 * @copyright Copyright (c) 2015-2017 oscshop.cn. 
 * @license   http://www.oscshop.cn/license.html License
 * ==========================================================================
 *
 * @author    李梓钿
 *
 */
 
namespace osc\payment\controller;
use osc\common\controller\Base;
use think\Db;
class TuanAlipay extends Base{
	
	//团购下单处理
	public function process($id){
		
		return $this->alipay_url(osc_service('common','Tuan')->add_order($id,session('shipping_address_id'),session('payment_method')));
	}
	
	public function alipay_url($order){		
		
		if($order['order_id']){
			
			$payment=payment_config('alipay');
			
			$payment['notify_url']=request()->domain().url('payment/Alipay/alipay_notify');					
					
			$payment['return_url']=request()->domain().url('payment/Alipay/alipay_return');//同步通知
			$payment['order_type']='goods_buy';
			$payment['subject']=$order['subject'];
			$payment['name']=$order['name'];
			$payment['pay_order_no']=$order['pay_order_no'];
			$payment['pay_total']=$order['pay_total'];					

			$alipay= new \payment\alipay\Alipay($payment);
			
			$url= $alipay->get_payurl();
			//删除购物车中的记录			
			osc_service('common','Tuan')->clear_cart($order['uid']);			
			
			return array('url'=>$url);
		}		
	}

}
